<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./js/vue.js"></script>
  </head>
  <body>
    <div id="app">
      <input type="text" v-model="msg" />
      <ul>
        <li v-for="item in filterPerson" :key="item.id">
          name:{{item.name}}---sex{{item.sex}}
        </li>
      </ul>
    </div>
  </body>
</html>
<script>
  Vue.config.productionTip = false;
  const vm = new Vue({
    el: '#app',
    data() {
      return {
        msg: '',
        person: [
          { id: 1, name: 'Jay', sex: '男' },
          { id: 2, name: 'JJ', sex: '男' },
          { id: 3, name: 'Eson', sex: '男' },
          { id: 4, name: 'Esjj', sex: '女' },
          { id: 5, name: 'hello', sex: '女' },
        ],
        filterPerson: [],
      };
    },
    watch: {
      msg: {
        immediate: true,
        handler(newVal) {
          this.filterPerson = this.person.filter((item) => {
            return item.name.toLowerCase().includes(newVal.toLowerCase());
          });
        },
      },
    },
  });
</script>
